var express = require('express');
var router = express.Router();
var request = require('superagent');
var Promise = require('bluebird');
/* GET home page. */
router.get('/', function (req, res, next) {

    var url = 'https://cnodejs.org/api/v1/topics';

    request
        .get(url)
        .query('pages=1')
        .end(function (err, result) {
            if (err || !result.body.success) {
                res.send('Error' + err);
            } else {
                res.render('index', {content: result.body.data});
            }
        });

});

module.exports = router;
